import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: window.sessionStorage.getItem('user'),
    token: window.sessionStorage.getItem('token'),
    menus: [],
    selectItem:window.sessionStorage.getItem("selectItem")
  },
  getters: {
    menus: state => {
      return state.menus
    },
    user: state => {
      return state.user
    },
    token: state => {
      return state.token
    }

  },
  mutations: {
    SET_USER: (state, user) => {
      state.user = user
      window.sessionStorage.setItem("user", user)
    },

    SET_TOKEN: (state, token) => {
      state.token = token
      window.sessionStorage.setItem("token", token)
    },
    SET_MENU: (state, menus) => {
      state.menus = menus
    },

    RESET_STATE(state) {
      state.menus = []
      state.user = null
      state.token = ""
    },


  },
  actions: {
  },
  modules: {
  }
})
